/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.pig4cloud.pigx.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.system.dto.SystemSymbolAddDTO;
import com.pig4cloud.pigx.system.dto.SystemSymbolEditDTO;
import com.pig4cloud.pigx.system.entity.SystemSymbol;
import com.pig4cloud.pigx.system.service.SystemSymbolService;
import com.pig4cloud.pigx.system.vo.SystemSymbolOptionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * 币对
 *
 * @since 2022-11-23 15:15:20
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/symbol")
@Api(value = "symbol", tags = "币对管理")
public class SystemSymbolController {

    private final SystemSymbolService systemSymbolService;

    /**
     * 分页查询
     *
     * @param page      分页条件
     * @param condition 查询条件
     * @return {@link R< Page< SystemSymbol>>}
     * @since 2022/11/24 10:48
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public R<Page<SystemSymbol>> page(Page<SystemSymbol> page, SystemSymbol condition) {
        return R.ok(systemSymbolService.page(page, condition));
    }

    /**
     * 根据id查询详情
     *
     * @param id id
     * @return {@link R< SystemSymbol>}
     * @since 2022/11/24 11:21
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    public R<SystemSymbol> getById(@PathVariable("id") Long id) {
        return R.ok(systemSymbolService.getById(id));
    }

    /**
     * 新增币对
     *
     * @param dto 数据
     * @return {@link R< Object>}
     * @since 2022/11/24 11:30
     */
    @ApiOperation(value = "新增币对", notes = "新增币对")
    @SysLog("新增币对")
    @PostMapping
    public R<Object> add(@Validated @RequestBody SystemSymbolAddDTO dto) {
        systemSymbolService.add(dto);
        return R.ok();
    }

    /**
     * 修改币对
     *
     * @param dto 数据
     * @return {@link R< Object>}
     * @since 2022/11/24 11:30
     */
    @ApiOperation(value = "修改币对", notes = "修改币对")
    @SysLog("修改币对")
    @PutMapping
    public R<Object> edit(@Validated @RequestBody SystemSymbolEditDTO dto) {
        systemSymbolService.edit(dto);
        return R.ok();
    }

    /**
     * 根据id逻辑删除
     *
     * @param id id
     * @return {@link R< Object>}
     * @since 2022/11/24 14:26
     */
    @ApiOperation(value = "通过id删除币对", notes = "通过id删除币对")
    @SysLog("通过id删除币对")
    @DeleteMapping("/{id}")
    public R<Object> del(@PathVariable Long id) {
        systemSymbolService.del(id);
        return R.ok();
    }

    /**
     * 查询选项数据
     *
     * @return {@link R< List< SystemSymbolOptionVO>}
     * @since 2022/11/24 14:26
     */
    @ApiOperation(value = "查询选项数据", notes = "查询选项数据")
    @GetMapping("/option")
    public R<List<SystemSymbolOptionVO>> option() {
        return R.ok(systemSymbolService.option());
    }

    /**
     * 查询价格
     *
     * @param name 币对名称
     * @return {@link R< BigDecimal>}
     * @since 2022/12/10 15:01
     */
    @GetMapping("/price/{name}")
    public R<BigDecimal> getPrice(@PathVariable("name") String name,@RequestParam("platformId") Long platformId) {
        return R.ok(systemSymbolService.getPrice(name,platformId));
    }
}
